package com.yuerlive.rainbow.widget;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;

import com.yuerlive.rainbow.R;
import com.yuerlive.rainbow.utils.DeviceUtils;

/**
 * Created by Admin on 2017/7/18.
 */

public class ButtomDialog extends Dialog {
    private Context context;
    public ButtomDialog(@NonNull Context context) {
        super(context);
        this.context=context;
    }

    public ButtomDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
        this.context=context;
    }

    public ButtomDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        this.context=context;
    }
    private void init(){
        //设置宽度,设置在底部
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = this.getWindow().getAttributes();
        lp.width = (int) (display.getWidth()); //设置宽度
        lp.height= DeviceUtils.dp2px(context,320);
        lp.gravity = Gravity.BOTTOM;
        this.getWindow().setAttributes(lp);
        this.getWindow().setWindowAnimations(R.style.shareDialog);
        this.setCanceledOnTouchOutside(true);
    }
    public void setContentView2(View view){
        this.setContentView(view);
        init();
    }
}
